<?php

namespace STAGE\StageBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use STAGE\UserBundle\Entity\UserRepository;
class StagePersonneType extends AbstractType {

    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder
                ->add('role')
                ->add('user', 'entity', array(
                    'class' => 'STAGE\UserBundle\Entity\User',
                    'query_builder' => function(UserRepository $er) {
                return $er->createQueryBuilder('e')
                        ->where('e.roles LIKE :etudiant')
                        ->setParameter('etudiant', '%ROLE_ENSEIGNANT%');
                ;
            }
                ))
        ;
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver) {
        $resolver->setDefaults(array(
            'data_class' => 'STAGE\StageBundle\Entity\StagePersonne'
        ));
    }

    /**
     * @return string
     */
    public function getName() {
        return 'stage_stagebundle_stagepersonne';
    }

}
